package demo;

import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;

import javax.net.ssl.SSLEngine;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.nio.file.Files;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Arrays;

/**
 * @author lingkang
 * @create by 2024/5/14 9:26
 */
public class Demo13 {
    public static void main(String[] args) throws Exception {
        String key="-----BEGIN CERTIFICATE-----\n" +
                "MIIEHDCCAwSgAwIBAgISAw2OhB63BzBgdzTzCtbYaebUMA0GCSqGSIb3DQEBCwUA\n" +
                "MDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQD\n" +
                "EwJSMzAeFw0yNDA1MTMwNTE2MjVaFw0yNDA4MTEwNTE2MjRaMBcxFTATBgNVBAMT\n" +
                "DGxpbmdrYW5nLnRvcDBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABNWO1mpGE5ak\n" +
                "3xt4OWvCeeNiqKbnySCtNEO5id0B3kApVPfVvO4Z0T3iTx3TKrRHxu8sMX4SvwM9\n" +
                "nt/N3SZlEeyjggIQMIICDDAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0lBBYwFAYIKwYB\n" +
                "BQUHAwEGCCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFCpUpy0GsWGL\n" +
                "F1IJgXH  wsh7jLkMB8GA1UdIwQYMBaAFBQusxe3WFbLrlAJQOYfr52LFMLGMFUG\n" +
                "CCsGAQUFBwEBBEkwRzAhBggrBgEFBQcwAYYVaHR0cDovL3IzLm8ubGVuY3Iub3Jn\n" +
                "MCIGCCsGAQUFBzAChhZodHRwOi8vcjMuaS5sZW5jci5vcmcvMBcGA1UdEQQQMA6C\n" +
                "DGxpbmdrYW5nLnRvcDATBgNVHSAEDDAKMAgGBmeBDAECATCCAQYGCisGAQQB1nkC\n" +
                "BAIEgfcEgfQA8gB3AO7N0GTV2xrOxVy3nbTNE6Iyh0Z8vOzew1FIWUZxH7WbAAAB\n" +
                "j3CYYmwAAAQDAEgwRgIhANXaeevlnYaar/m3tTgFgn42rxuTxx/j3MZEzG2pM0px\n" +
                "AiEAkEUrqnmQwtU2ws3dQXaf4h9CBRuwydJkX67/FgNy2kEAdwBIsONr2qZHNA/l\n" +
                "agL6nTDrHFIBy1bdLIHZu7 rOdiEcwAAAY9wmGMVAAAEAwBIMEYCIQDemqQDHzcV\n" +
                "k6d3nVGU2YxDmz3pUnmmg5ITT7VH11I7FgIhAOOMK9ziUxrq31lHxOosCO6MbacW\n" +
                "2ztQu3WFXRVjMCs9MA0GCSqGSIb3DQEBCwUAA4IBAQCqzoDMLI7HQDQeKi2Fa/gc\n" +
                "dqby5kssZD6P1PBg98mQjqFIuXOM40KekAUw3kWn63k0Zrjl53WEsKClfifelBHZ\n" +
                "bsGWs4g B8flbMU5AKUEuaxbUthnsCXcvQRlEuFRTQnCe9nE0EYe5Ri9unsHRwvR\n" +
                "W/Gr5xYmV ab1l4H581xy5SIGHirarjEdsAy77VvxP/M8RPIC3JuWssHpFsBvQyU\n" +
                "IhPgqFiAvMIXqtIhppq653qTnflpc4eAcwrB8W2RgnWGrn/pIWAZxCuiW40b2QT0\n" +
                "yIoP/MZWUt/KtK7YSDcMBJ7bGL3aKvZXsfJk7/t OxWWXWlq7TCFLdKzuNn6kXkj\n" +
                "-----END CERTIFICATE-----\n" +
                "\n" +
                "-----BEGIN CERTIFICATE-----\n" +
                "MIIFFjCCAv6gAwIBAgIRAJErCErPDBinU/bWLiWnX1owDQYJKoZIhvcNAQELBQAw\n" +
                "TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh\n" +
                "cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMjAwOTA0MDAwMDAw\n" +
                "WhcNMjUwOTE1MTYwMDAwWjAyMQswCQYDVQQGEwJVUzEWMBQGA1UEChMNTGV0J3Mg\n" +
                "RW5jcnlwdDELMAkGA1UEAxMCUjMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK\n" +
                "AoIBAQC7AhUozPaglNMPEuyNVZLD ILxmaZ6QoinXSaqtSu5xUyxr45r XXIo9cP\n" +
                "R5QUVTVXjJ6oojkZ9YI8QqlObvU7wy7bjcCwXPNZOOftz2nwWgsbvsCUJCWH jdx\n" +
                "sxPnHKzhm /b5DtFUkWWqcFTzjTIUu61ru2P3mBw4qVUq7ZtDpelQDRrK9O8Zutm\n" +
                "NHz6a4uPVymZ DAXXbpyb/uBxa3Shlg9F8fnCbvxK/eG3MHacV3URuPMrSXBiLxg\n" +
                "Z3Vms/EY96Jc5lP/Ooi2R6X/ExjqmAl3P51T c8B5fWmcBcUr2Ok/5mzk53cU6cG\n" +
                "/kiFHaFpriV1uxPMUgP17VGhi9sVAgMBAAGjggEIMIIBBDAOBgNVHQ8BAf8EBAMC\n" +
                "AYYwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMBMBIGA1UdEwEB/wQIMAYB\n" +
                "Af8CAQAwHQYDVR0OBBYEFBQusxe3WFbLrlAJQOYfr52LFMLGMB8GA1UdIwQYMBaA\n" +
                "FHm0WeZ7tuXkAXOACIjIGlj26ZtuMDIGCCsGAQUFBwEBBCYwJDAiBggrBgEFBQcw\n" +
                "AoYWaHR0cDovL3gxLmkubGVuY3Iub3JnLzAnBgNVHR8EIDAeMBygGqAYhhZodHRw\n" +
                "Oi8veDEuYy5sZW5jci5vcmcvMCIGA1UdIAQbMBkwCAYGZ4EMAQIBMA0GCysGAQQB\n" +
                "gt8TAQEBMA0GCSqGSIb3DQEBCwUAA4ICAQCFyk5HPqP3hUSFvNVneLKYY611TR6W\n" +
                "PTNlclQtgaDqw 34IL9fzLdwALduO/ZelN7kIJ m74uyA eitRY8kc607TkC53wl\n" +
                "ikfmZW4/RvTZ8M6UK 5UzhK8jCdLuMGYL6KvzXGRSgi3yLgjewQtCPkIVz6D2QQz\n" +
                "CkcheAmCJ8MqyJu5zlzyZMjAvnnAT45tRAxekrsu94sQ4egdRCnbWSDtY7kh BIm\n" +
                "lJNXoB1lBMEKIq4QDUOXoRgffuDghje1WrG9ML Hbisq/yFOGwXD9RiX8F6sw6W4\n" +
                "avAuvDszue5L3sz85K EC4Y/wFVDNvZo4TYXao6Z0f lQKc0t8DQYzk1OXVu8rp2\n" +
                "yJMC6alLbBfODALZvYH7n7do1AZls4I9d1P4jnkDrQoxB3UqQ9hVl3LEKQ73xF1O\n" +
                "yK5GhDDX8oVfGKF5u decIsH4YaTw7mP3GFxJSqv3 0lUFJoi5Lc5da149p90Ids\n" +
                "hCExroL1 7mryIkXPeFM5TgO9r0rvZaBFOvV2z0gp35Z0 L4WPlbuEjN/lxPFin \n" +
                "HlUjr8gRsI3qfJOQFy/9rKIJR0Y/8Omwt/8oTWgy1mdeHmmjk7j1nYsvC9JSQ6Zv\n" +
                "MldlTTKB3zhThV1 XWYp6rjd5JW1zbVWEkLNxE7GJThEUG3szgBVGP7pSWTUTsqX\n" +
                "nLRbwHOoq7hHwg==\n" +
                "-----END CERTIFICATE-----\n" +
                "\n";
        CertificateFactory factory = CertificateFactory.getInstance("X.509");
        Certificate cert = factory.generateCertificate(new ByteArrayInputStream(key.getBytes()));
        // Certificate cert = factory.generateCertificate(Files.newInputStream(new File("C:\\Users\\Administrator\\Desktop\\temp\\key\\fullchain.pem").toPath()));

        X509Certificate x509Cert = (X509Certificate) cert;

        // 输出证书信息
        System.out.println("Subject: " + x509Cert.getSubjectDN().getName());
        System.out.println("Issuer: " + x509Cert.getIssuerDN().getName());
        System.out.println("Not Before: " + x509Cert.getNotBefore());
        System.out.println("Not After: " + x509Cert.getNotAfter());
    }
}
